const express = require('express')
const history = require('connect-history-api-fallback')
const xlsx = require('xlsx')
const app = express()

app.use(history())
app.use(express.static(__dirname + '/dist'))
app.get('/excel', (req, res) => {
  const workbook = xlsx.readFile('./assets/行政村监控点位.xlsx')
  const sheetNames = workbook.SheetNames
  const sheet = workbook.Sheets[sheetNames[0]]
  const data = xlsx.utils.sheet_to_json(sheet)

  const arr = []
  for (let i = 0; i < data.length; i++) {
    const obj = {
      geometry: {
        coordinates: [data[i]['经度'], data[i]['纬度']],
        type: 'Point'
      },
      type: 'Feature',
      properties: {
        name: data[i]['村委会及各村入口名称'],
        info: data[i]['有无电网资源'],
        area: data[i]['行政区']
      }
    }
    arr.push(obj)
  }
  res.json(arr)
})

app.listen(3010)
